package com.open.capacity.exam.controller;

import cn.hutool.db.Page;
import com.open.capacity.common.model.ExamAnswer;
import com.open.capacity.common.model.ExamPaperUser;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.exam.service.ExamService;
import com.open.capacity.exam.vo.CheckPaper;
import com.open.capacity.exam.vo.ExamAnswerVo;
import com.open.capacity.exam.vo.PaperVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/exam")
@Api(tags = "考试管理")
public class ExamController {
    @Autowired
    private ExamService examService;
    private ExamPaperUser paperUser;
    private Integer[] quesids;
    private Integer[] checks;

    /**
     * 进行考试
     * 查询考试列表，根据用户id查询
     * @param param
     * @return
     */
    @GetMapping("/findExam")
    public PageResult<PaperVo> findExam(@RequestParam Map<String,Object> param){
        return examService.findExam(param);
    }

    /**
     * 答卷
     * @param answer
     * @return
     */
    @PostMapping("/answer")
    public Result answer(@RequestParam("userid") String userid,@RequestParam Integer expaid,
    @RequestParam("questionId[]")Integer[] quesid,@RequestParam("questionAnswer[]") String[] answer){
        return examService.answer(userid,expaid,quesid,answer);
    }

    /**
     * 查询考生是否考试
     * @param param 用户id，试卷id
     * @return
     */
    @GetMapping("/findAnswer")
    public PageResult<ExamPaperUser> findAnswer(@RequestParam Map<String,Object> param){
        return examService.findAnswer(param);
    }

    /**
     * 查看答题结果
     * @param param 用户id和试卷id
     * @return
     */
    @RequestMapping("/findResult")
    public PageResult<ExamAnswerVo> findResult(@RequestParam Map<String,Object> param){
        return examService.findResult(param);
    }

    /**
     * 查询教师对应的小组成员 已提交的试卷
     * @param param teacid（教练id）
     * @return
     */
    @GetMapping("/findSubmitExam")
    public PageResult<PaperVo> findSubmitExam(@RequestParam Map<String,Object> param){
        return examService.findSubmitExam(param);
    }

    /**
     * 批改试卷
     * @param checkPapers
     * @return
     */
    @PostMapping("/updateExam")
    public Result updateExam(@RequestBody List<CheckPaper> checkPapers){
        return examService.updateExam(checkPapers);
    }
}
